﻿// This file is part of Code4Public (http://code4public.codeplex.com)
// Copyright 2011 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
// ------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Code4Public.Parsing
{
    public class Expression
    {
        public ExpressionType Type { get; private set; }
        public string Content { get; private set; }
        public string Group { get; private set; }

        public Expression(string content, ExpressionType type, string group)
        {
            Debug.Assert(content != null);
            Debug.Assert(group != null);

            this.Type = type;
            this.Content = content;
            this.Group = group;
        }

        public Expression(string content, ExpressionType type) : this(content, type, "")
        {
        }

        public override string ToString()
        {
            if (Type == ExpressionType.Newline)
            {
                return String.Format("({0})", Type.ToString());
            }
            else
            {
                return String.Format("({0} --> {1}{2})", Content, Type.ToString(), Group.Length > 0 ? " --> " + Group : "");
            }
        }
    }
}
